package musictrackrecommendation;

import lastfm.LastfmDataset;
import evaluation.EvaluationMetric;
import randomwalk.RandomWalkWithRestarts;
import randomwalk.restricted.RestrictedRandomWalk;
import similarity.UserSimalarityCalculation;
import simulation.RandomWalkWithRestartsSimulation;

public class Main {

	public static void main(String[] args) {
		long startTime = System.currentTimeMillis();
		
		recommend();
		//simulate();
		
		long finishTime = System.currentTimeMillis();;
		System.out.println("Total execution time (sec): " 
				+ (finishTime - startTime)/1000);
	}
	
	public static void recommend() {
		RandomWalkWithRestarts rwr = new RandomWalkWithRestarts();
		
		ExperimentParameters.setCosineUsersRecommendation(3148);
		rwr.randomWalkWithRestarts();
		
		ExperimentParameters.setFullUserTrackRecommendation(3148);
		rwr.randomWalkWithRestarts();
	}
	
	public static void restrictedRecommendation() {
		ExperimentParameters.setRestrictedRecommendation();
		
		int[] users = (new LastfmDataset()).getUserList();
		for (int i = 4; i < 5; i++) {
			for (int j = 35; j > 32; j--) {
				RestrictedRandomWalk rrw = new RestrictedRandomWalk(i,i,j,j);
				System.out.print(i + "-");System.out.print(i + "-");
				System.out.print(j + "-");System.out.println(j);
				
				long start = System.currentTimeMillis();
				long finish = 0;
				
				for (int k = 0; k < 100; k++) {
					rrw.recommend(users[k]);
					finish = System.currentTimeMillis();
					System.out.println("Time: " 
							+ (finish - start)/1000);
					start = finish;
				}
				
				EvaluationMetric[] metrics = ExperimentParameters.getInstance().getMetrics();
				
				for(EvaluationMetric metric : metrics) {
					metric.printMeanMetricValue();
				}
				
				ExperimentParameters.setRestrictedRecommendation();
			}
		}
	}
	
	public static void simulate() {
		ExperimentParameters.setFullUserTrackRecommendation(1);
		int[] users = (new LastfmDataset()).getUserList();
		
		
		for (int userId : users) {
		
		for (int i = 10000; i < 15001; i+=1000) {
			long startTime = System.currentTimeMillis();
			RandomWalkWithRestartsSimulation sim = 	new RandomWalkWithRestartsSimulation(userId);
			
			System.out.println(i +"-step simulation:");
			
			sim.randomWalkWithRestarts(i);
			
			long finishTime = System.currentTimeMillis();;
			System.out.println("Simulation time (sec): " 
					+ (finishTime - startTime)/1000);
			
		}
		}
	}
	
	public static void similarity() {
		UserSimalarityCalculation sim = new UserSimalarityCalculation();
		sim.calcSimilarity();
	}
}
